package chapter2;

import static org.junit.Assert.*;

import org.junit.Test;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class ExecuteJavaScript {

	@Test
	public void testJavaScriptCalls() throws Exception
	{
	WebDriver driver = new FirefoxDriver();
	driver.get("http://www.google.com");
	
	JavascriptExecutor js = (JavascriptExecutor) driver;
	String title = (String) js.executeScript
	("return document.title");
	assertEquals("Google", title);
	long links = (Long) js.executeScript("var links = document.getElementsByTagName('A'); return links.length");
	assertEquals(35, links);
	driver.quit();
	}
	
}
